local skill = fk.CreateSkill{
  name = "action__nisiwohuo_skill",
}

Fk:loadTranslationTable{
  ["action__nisiwohuo"] = "你死我活",
  ["action__nisiwohuo_skill"] = "你死我活",
  [":action__nisiwohuo"] = "锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：你 <br /><b>效果</b>：所有其他角色开始“乱武”（对距离最近的角色使用杀或失去1点体力），直到有角色死亡。（不可响应）",
  ["#action__nisiwohuo_skill"] = "令所有其他角色开始“乱武”（对距离最近的角色使用杀或失去1点体力），直到有角色死亡",
}


skill:addEffect("cardskill", {
  mute = true,
  name = "action__nisiwohuo",
  prompt = "#action__nisiwohuo_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    cardUseEvent.disresponsiveList = table.simpleClone(Fk:currentRoom().players)
    if not cardUseEvent.tos or #cardUseEvent.tos == 0 then
      cardUseEvent.tos = { cardUseEvent.from }
    end
  end,
  on_effect = function(self, room, effect)
    room:setTag("action__nisiwohuo_quit","0")
    for i =1, 99 do
      for _, target in ipairs(room:getOtherPlayers(effect.to)) do
        if not target.dead then
          local other_players = table.filter(room:getOtherPlayers(target, false), function(p)
            return not p:isRemoved()
          end)
          local luanwu_targets = table.filter(other_players, function(p2)
            return table.every(other_players, function(p1)
              return target:distanceTo(p1) >= target:distanceTo(p2)
            end)
          end)
          local use = room:askToUseCard(target, {
            skill_name = self.name,
            pattern = "slash",
            prompt = "你死我活：对距离最近的一名角色使用一张【杀】，否则失去1点体力",
            cancelable = true,
            extra_data = {
              exclusive_targets = table.map(luanwu_targets, Util.IdMapper),
              bypass_times = true,
            }
          })
          if use then
            use.extraUse = true
            room:useCard(use)
          else
            room:loseHp(target, 1, self.name)
          end
          if room:getTag("action__nisiwohuo_quit") == "can" then
            break
          end
        end
      end
      if room:getTag("action__nisiwohuo_quit") == "can" then
        break
      end
    end
  end,
})

skill:addEffect(fk.Deathed, {
  mute = true,
  global = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player.room:getTag("action__nisiwohuo_quit") ~= nil
  end,
  on_use = function(self, event, target, player, data)
    player.room:setTag("action__nisiwohuo_quit", "can")
  end,
})



return skill